import request from "@/utils/request";
import type { AddOrUpdateCartParams, CartResult } from "@/type/CartType";
import type { ResponseType } from "@/type/ResponseType";

enum Enum {
   fetchCartListAPI = "/cart/list",
   addCartAPI = "/cart/add",
   deleteCartAPI = "/cart/clear",
   updateCartAPI = "/cart/update",
   fetchCartTotalAPI="/cart/total"
}

/**
 * @description 获取购物车商品列表的接口
 * */
export const fetchCartListAPI = async () => request.get<CartResult, ResponseType<CartResult>>(Enum.fetchCartListAPI);

/**
 * @description 添加商品到购物车的接口
 * */
export const addCartAPI = (addParams: AddOrUpdateCartParams) => request.post<number, ResponseType<number>>(Enum.addCartAPI, addParams);

/**
 * @description 删除购物车商品的接口
 * */
export const deleteCartAPI = (cartIds: number[]) => request.post<number, ResponseType<number>>(Enum.deleteCartAPI, { cartIds });

/**
 * @description 更新购物车商品的接口
 * */
export const updateCartAPI = (data: AddOrUpdateCartParams) => request.post<number, ResponseType<number>>(Enum.updateCartAPI, data);

/**
 * @description 获取购物车商品总数量的接口
 * */
export const fetchCartTotalAPI=()=>request.get<{cartTotal:number}, ResponseType<{cartTotal:number}>>(Enum.fetchCartTotalAPI)
